import request from "@/utils/request";

const VERSION_API_URL = import.meta.env.VITE_VERSION_API_URL;

// 获取最新版本信息
export function getLatestVersion() {
  return request({
    url: `${VERSION_API_URL}/api/versions/latest`,
    method: "GET",
  });
}

// 版本比较函数
export function compareVersions(v1, v2) {
  const v1Parts = v1.split(".").map(Number);
  const v2Parts = v2.split(".").map(Number);

  for (let i = 0; i < 3; i++) {
    if (v1Parts[i] > v2Parts[i]) return 1;
    if (v1Parts[i] < v2Parts[i]) return -1;
  }
  return 0;
}
